<#assign basePath=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

	<#include '/common/common-css.html'>
</head>

<body>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="myForm">
                    	<div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>上级机构：</label>
                            <div class="col-sm-8">
                                <input id="parent" name="parent" class="form-control" type="text" disabled="disabled">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>名称：</label>
                            <div class="col-sm-8">
                                <input id="name" name="name" class="form-control" type="text">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger"> </sapn>描述：</label>
                            <div class="col-sm-8">
                                <input id="description" name="description" class="form-control" type="text">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <#include '/common/common-js.html'>
    <script type="text/javascript">
    $().ready(function() {
    	$("#parent").val("${parent.name}");
    	
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#myForm").validate({
            rules: {
            	name: {
                    required: !0
                }
            },
            messages: {
            	name: {
                    required: e + "请输入名称"
                }
            },
            submitHandler:function(form){
            	var data = {
	            	"pId" : "${parent.id}",
            		"name" : $("#name").val(),
	            	"description" : $("#description").val()
            	};
    			$.ajax({    
    		        type: "post",   
    		        url: "${basePath}/organization/save?t=" + Math.random(),   
    		        data : data,
    		        dataType: "json",    
    		        success: function (data) { 
    		        	if(data.error){
    						layer.msg(data.msg,{icon:2,time:1000});
    					}else{
    						if(data == 1){
        		        		parent.table.ajax.reload();
        		            	var index = parent.layer.getFrameIndex(window.name);
        		        		parent.layer.close(index);
        		        		//重新异步加载树
        						parent.zTree.reAsyncChildNodes(null, "refresh");
        		        		parent.layer.msg('添加成功!',{icon:1,time:1000});
        		        	}
    					}
    		        },
    		        error:function(e) {
    					console.log(e);
    				}
    		    }) 
    		}
        }); 
    });
    
    function add(){
    	$("#myForm").submit();
    }
    </script>
</body>
</html>


